package com.eyas.im.gui.swing.index;

import com.eyas.im.protocol.decoder.Decoder;
import com.eyas.im.protocol.encoder.Encoder;
import com.eyas.im.protocol.protocol.StringProtocol;
import com.eyas.im.server.nio.handler.AbstractNioServerSocketHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class JFrameServerHandler extends AbstractNioServerSocketHandler<StringProtocol> {
    private final static Logger logger = LoggerFactory.getLogger(JFrameServerHandler.class);
    private SocketAddress socketAddress; //client端的信息
    public JFrameServerHandler(Encoder<StringProtocol> encoder, Decoder<StringProtocol> decoder, int bufferCapacity) {
        super(encoder, decoder, bufferCapacity);
    }

    @Override
    public void afterDecodeData(StringProtocol decodeData) {

    }

    @Override
    public void afterAccept(SocketAddress socketAddress) {
        logger.debug("获取到一个客户端连接[ip:{},port:{}]",
                ((InetSocketAddress)socketAddress).getHostName(),((InetSocketAddress)socketAddress).getPort());
        this.socketAddress = socketAddress;
    }

    @Override
    public void beforeClose() {
        logger.debug("client[ip:{},port:{}]即将断开",
                ((InetSocketAddress)this.socketAddress).getHostName(),((InetSocketAddress)this.socketAddress).getPort());
    }
}
